// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()
const db=cloud.database()
const _=db.command
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let openid = wxContext.OPENID;
  try{
    let pro = await db.collection('buyRecord').where({
      openid:openid
    }).get();

    return {
      code:0,
      mes:'获取成功',
      data: pro.data[0]
    };
  }catch(e){
    return{
      code:1,
      mes:'获取失败',
      data:null
    }
  }

}